from django.shortcuts import render
from django.http import HttpResponse
from .models import Sentence, Lesson
import random


brand = '酷语 CooYuu'


def learn(request):
    lessons = Lesson.objects.all()
    context = {
        'brand': brand,
        'lessons': lessons
    }
    return render(request, "learn/learn.html", context)


def lesson(request, lesson_id):
    if lesson_id == 0: # 表示随机，否则根据选定的课程进行学习
        sentence = Sentence.objects.first()
        lesson = '随机'
    else:
        lesson = Lesson.objects.get(id=lesson_id)
        sentence = random.choice(Sentence.objects.filter(lesson=lesson))

    question, answer, options = sentence.create_question()
    context = {
        'brand': brand,
        'question': question,
        'answer': answer,
        'options': options,
        'lesson': lesson,
        'sentence': sentence
    }
    return render(request, "learn/lesson.html", context)


def sentence(request):
    '''
    提交新的句子，管理已经提交的句子。了解自己对已经学的句子的掌握情况
    '''
    ...